import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/bill_detail/bill_detail_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/manage_bank/manage_bank_type_page.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/settle_detail/settle_detail_page.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/button_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'wallet_enterprise_controller.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';

class WalletEnterprisePage extends GetView<WalletEnterpriseController> {
  static const path = '/walletEnterprise';
  const WalletEnterprisePage({super.key});

  @override
  Widget build(BuildContext context) {
    final double top = MediaQuery.of(context).padding.top;
    return Scaffold(
      body: Stack(
        children: [
          SizedBox(
            width: context.width,
            child: ImageAssetWidget(
              width: double.infinity,
              height: 173.px,
              imageUrl: 'static/images/wallet/top_bg.png',
            ),
          ),
          Positioned(
            right: 0,
            bottom: 0,
            child: ImageAssetWidget(
              width: 216.px,
              height: 253.px,
              imageUrl: 'static/images/wallet/bottom_bg.png',
            ),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, top, 0, 24.px),
            child: Column(
              children: [
                CustomAppBar2(title: '汇付钱包企业版', context: context),
                Expanded(
                  child: RefreshIndicator(
                    backgroundColor: Colors.transparent,
                    color: Colors.white,
                    onRefresh: controller.handleRefresh,
                    child: _buildPersonalList(context),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),

      // Column(
      //   children: [
      //     Container(
      //       width: double.infinity,
      //       decoration: const BoxDecoration(
      //         gradient: LinearGradient(
      //           begin: Alignment.topCenter,
      //           end: Alignment.bottomCenter,
      //           colors: [Color(0xFFB2E9E2), Colors.white],
      //         ),
      //       ),
      //       child: Column(
      //         children: [
      //           const SizedBox(height: 32),
      //           const Text(
      //             '可用余额',
      //             style: TextStyle(fontSize: 18.px, color: Colors.black54),
      //           ),
      //           const SizedBox(height: 8),
      //           Obx(
      //             () => Text(
      //               '￥ ${controller.balance.value.toStringAsFixed(2)}',
      //               style: const TextStyle(
      //                 fontSize: 48,
      //                 fontWeight: FontWeight.bold,
      //                 color: Color(0xFF4B7B5A),
      //               ),
      //             ),
      //           ),
      //           const SizedBox(height: 16),
      //           Container(
      //             decoration: BoxDecoration(
      //               borderRadius: BorderRadius.circular(24),
      //               color: const Color(0xFFE6FFF8),
      //             ),
      //             child: TextButton(
      //               onPressed: () {},
      //               child: const Padding(
      //                 padding: EdgeInsets.symmetric(
      //                   horizontal: 32,
      //                   vertical: 8,
      //                 ),
      //                 child: Text(
      //                   '提现',
      //                   style: TextStyle(
      //                     fontSize: 20.px,
      //                     color: Color(0xFF4B7B5A),
      //                   ),
      //                 ),
      //               ),
      //             ),
      //           ),
      //           const SizedBox(height: 24),
      //         ],
      //       ),
      //     ),
      //     Expanded(
      //       child: ListView.separated(
      //         padding: const EdgeInsets.only(top: 24),
      //         itemCount: controller.menuList.length,
      //         separatorBuilder: (_, __) => const SizedBox(height: 8),
      //         itemBuilder: (context, index) {
      //           final title = controller.menuList[index];
      //           return _menuItem(
      //             title,
      //             onTap: () => _onMenuTap(context, index),
      //           );
      //         },
      //       ),
      //     ),
      //   ],
      // ),
    );
  }

  Widget _buildPersonalList(BuildContext context) {
    return SingleChildScrollView(
      physics: AlwaysScrollableScrollPhysics(),
      controller: controller.scrollController,
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 24),
        child: Column(
          children: [
            const SizedBox(height: 32),
            const Text(
              '可用余额',
              style: TextStyle(fontSize: 14, color: AppColors.fontColorBlack),
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 8),
            Obx(
              () => Text(
                '${controller.detail.value}',
                style: const TextStyle(
                  color: AppColors.fontColorGreen,
                  fontSize: 48,
                  fontWeight: FontWeight.bold,
                ),
                textAlign: TextAlign.center,
              ),
            ),
            const SizedBox(height: 24),
            Center(
              child: ButtonWidget(
                label: '提现',
                height: 32.px,
                width: 106.px,
                fontSize: 12.px,
                fontColor: AppColors.fontColorGreen,
                imageBg: 'static/images/wallet/wallet_opne_btn.png',
                contentType: ContentType.text,
                onPressed: controller.withdraw,
              ),
            ),
            const SizedBox(height: 40),
            _menuItem('结算明细', controller.onSettlementDetail),
            _menuItem('账单明细', controller.onBillDetail),
            _menuItem('银行卡管理', controller.onBankCardManage),
            _menuItem('开户信息', controller.openAccountInfo),
          ],
        ),
      ),
    );
  }

  Widget _menuItem(String title, VoidCallback onTap) {
    return Container(
      margin: const EdgeInsets.only(bottom: 16),
      decoration: BoxDecoration(
        color: const Color(0xFFF7F7F7),
        borderRadius: BorderRadius.circular(12),
      ),
      child: ListTile(
        title: Text(title, style: const TextStyle(fontSize: 18)),
        trailing: const Icon(
          Icons.arrow_forward_ios,
          size: 18,
          color: Colors.black45,
        ),
        onTap: onTap,
      ),
    );
  }
}

//   Widget _menuItem(String title, {VoidCallback? onTap}) {
//     return Container(
//       margin: const EdgeInsets.symmetric(horizontal: 16),
//       decoration: BoxDecoration(
//         color: const Color(0xFFF8F8F8),
//         borderRadius: BorderRadius.circular(16),
//       ),
//       child: ListTile(
//         title: Text(title, style: const TextStyle(fontSize: 18.px)),
//         trailing: const Icon(
//           Icons.arrow_forward_ios,
//           size: 18,
//           color: Colors.black45,
//         ),
//         onTap: onTap,
//       ),
//     );
//   }

//   void _onMenuTap(BuildContext context, int index) {
//     switch (index) {
//       case 0:
//         Get.toNamed(SettleDetailPage.path);
//         break;
//       case 1:
//         Get.toNamed(BillDetailPage.path);
//         break;
//       case 2:
//         Get.toNamed(ManageBankTypePage.path);
//         // Get.snackbar('提示', '银行卡管理页面待实现');
//         break;
//       case 3:
//         // Get.toNamed(OpenAccountInfoPage.path);
//         Get.snackbar('提示', '开户信息页面待实现');
//         break;
//     }
//   }
// }
